﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;

namespace Webservice.Tests
{
    [TestClass]
    public class StorageServiceTests
    {
        [TestMethod]
        public void RequestReports_Expect_List()
        {
            StorageService client = new StorageService();
            List<Contracts.Report> results = client.GetReports();

            Assert.IsInstanceOfType(results, typeof(List<Contracts.Report>));
        }

        [TestMethod]
        public void SendLogFile_Expect_SystemArgumentException()
        {
            StorageService client = new StorageService();
            string content = new StreamReader(@"Assets\BadCSV.csv").ReadToEnd();

            try
            {
                client.UploadLog(content);
            }
            catch(System.ArgumentException ex)
            {
                Assert.IsInstanceOfType(ex,typeof(System.ArgumentException),"Expected exception of type " + typeof(System.ArgumentException) + " but type of " + ex.GetType() + " was thrown instead.");
                return;
            }

            Assert.Fail("Expected exception of type " + typeof(System.ArgumentException) + " but no exception was thrown.");
        }

        [TestMethod]
        public void SendLogFile_Expect_No_Exceptions()
        {
            StorageService client = new StorageService();
            string content = new StreamReader(@"Assets\GoodCSV.csv").ReadToEnd();

            try
            {
                client.UploadLog(content);
            }
            catch (SystemException ex)
            {
                Assert.Fail("An unexpected exception was thrown. " + ex);
            }
        }

        [TestMethod]
        public void RequestReports_Expect_JSON_String()
        {

        }

        [TestMethod]
        public void RequestReport_Expect_JSON_String()
        {
            StorageService client = new StorageService();
            string contents = client.GetReport("2FMDK4KC9DBA59459_672ed19fc2524fbc833c2222e7bc4458");

            Debug.WriteLine(contents);

            StringAssert.StartsWith(contents, "{", "Contents are not a valid JSON string");
        }
    }
}